npiperelay & socatでWSLとWindowsのssh-agentを同期
from ssh-agent
from
Windows と WSL2 で同じ SSH key を使用する方法 | 岡山のWEB制作はKOMARI
Windows上のssh-agentをWSL2から利用する - 色々なメモ。
npiperelayをインストール
chocolatey
code:admin powershell
choco install npiperelay
またはReleases · jstarks/npiperelay · GitHubからDL
socatをインストール
code:wsl(sh)
sudo apt install socat
以下を追記
code:~/.bashrc(sh)
export SSH_AUTH_SOCK=$HOME/.ssh/agent.sock
# check socat process and the socket file
if ! pgrep -f "socat.*$SSH_AUTH_SOCK" >/dev/null || ! -S "$SSH_AUTH_SOCK" ; then
# clean up old processes and files
pkill -f "socat.*$SSH_AUTH_SOCK" 2>/dev/null
rm -f "$SSH_AUTH_SOCK"
# start new socat
(setsid socat UNIX-LISTEN:"$SSH_AUTH_SOCK",fork EXEC:"/mnt/c/path/to/npiperelay.exe -ei -s //./pipe/openssh-ssh-agent",nofork &) >/dev/null 2>&1
sleep 0.5
fi
/mnt/c/path/to/npiperelay.exeは適宜変更する
code:example
/mnt/c/ProgramData/chocolatey/lib/npiperelay/tools/npiperelay.exe
rupor-github/wsl-ssh-agentで紹介されてるwsl-ssh-agent/wsl-ssh-agent-relay at master · rupor-github/wsl-ssh-agent · GitHubとの違いは?
windows側、WSL側どちらからssh-addしても共有される
WSL側に.ssh/agent.sockというファイルができるが、消してはいけない
ただし接続がうまくいかないときはこれを消してターミナルを再起動してみる(再作成される)
WSLでssh-agentを使っているのに秘密鍵のパスワードを聞かれる場合
WindowsのOpenSSHのバージョンが古い
linux - Ssh fails to use private key from ssh-agent: communication with agent failed - Stack Overflow
$ ssh -V
WSL側よりWindows側が古いとcommunicationに失敗する?
Linux.icon
bash.icon